Skip to content

fix(encode): adjust max pack size for 32-bit targets to prevent overflow#65

Merged
genedna merged 2 commits into
libra-tools:mainfrom
yueneiqi:fix/encode-32bit-check
Jan 5, 2026
Merged

fix(encode): adjust max pack size for 32-bit targets to prevent overflow#65
genedna merged 2 commits into
libra-tools:mainfrom
yueneiqi:fix/encode-32bit-check

Conversation

@yueneiqi

@yueneiqi yueneiqi commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

When run buck2 build //... --target-platforms //platforms:i686-unknown-linux-gnu on ci, encounter:

error: this arithmetic operation will overflow
   --> vendor/src/internal/pack/encode.rs:758:18
    |
758 |             Some(1024 * 1024 * 1024 * 6), // 6GB
    |                  ^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `1073741824_usize * 6_usize`, which would overflow
    |
    = note: `#[deny(arithmetic_overflow)]` on by default

This PR fixes that.

Summary

  • make pack header size check 32-bit safe
  • adjust max pack size for 32-bit targets to prevent overflow

Testing

  • cargo test
  • cargo test --target i686-unknown-linux-gnu
  • ci log

This PR was primarily authored with Codex using GPT-5.2-Codex and then hand-reviewed by me. I AM responsible for every change made in this PR. I aimed to keep it aligned with our goals, though I may have missed minor issues. Please flag anything that feels off, I'll fix it quickly.

Signed-off-by: linfeng.ouyang <fyoylf@gmail.com>
@genedna
genedna requested a review from Copilot January 4, 2026 08:24
@genedna

genedna commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses 32-bit platform safety by preventing integer overflow in pack size calculations. The changes ensure that pack operations don't cause panics on 32-bit targets where usize is limited to ~4GB.

Key changes:

  • Modified cache memory size calculation to use wider arithmetic (u128) preventing overflow when computing 80% of memory limit
  • Adjusted test pack size limits to use 2GB on 32-bit targets instead of 6GB to fit within usize bounds
  • Added a regression test for 32-bit overflow scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/internal/pack/decode.rs Fixed cache memory calculation to prevent overflow using u128 intermediate type; added 32-bit specific test case
src/internal/pack/encode.rs Added platform-specific pack size limits in test helper to avoid overflow on 32-bit targets

Comment thread src/internal/pack/encode.rs
Comment thread src/internal/pack/decode.rs Outdated
Comment thread src/internal/pack/encode.rs Outdated
@yueneiqi
yueneiqi marked this pull request as draft January 4, 2026 08:41
@yueneiqi
yueneiqi marked this pull request as ready for review January 4, 2026 08:46
Signed-off-by: linfeng.ouyang <fyoylf@gmail.com>
@yueneiqi
yueneiqi force-pushed the fix/encode-32bit-check branch from 58a937d to 2f75678 Compare January 5, 2026 01:38
@genedna
genedna merged commit 90daceb into libra-tools:main Jan 5, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 12, 2026
genedna pushed a commit to genedna/git-internal that referenced this pull request Mar 15, 2026
…low (libra-tools#65)

* fix(encode): adjust max pack size for 32-bit targets to prevent overflow

Signed-off-by: linfeng.ouyang <fyoylf@gmail.com>

* fix(decode): 32-bit overflow in pack cache sizing

Signed-off-by: linfeng.ouyang <fyoylf@gmail.com>

---------

Signed-off-by: linfeng.ouyang <fyoylf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants